using Godot;
using System;

public partial class Player : CharacterBody2D
{
    [Export]
    public float Speed = 300.0f;
    
    [Export]
    public float JumpVelocity = -400.0f;
    
    // 获取重力值，以便在项目设置中覆盖
    public float GetGravity()
    {
        return ProjectSettings.GetSetting("physics/2d/default_gravity").AsSingle();
    }
    
    public override void _Process(double delta)
    {
        Vector2 velocity = Vector2.Zero;
        
        // 简单的键盘输入检测
        if (Input.IsKeyPressed(Key.A) || Input.IsKeyPressed(Key.Left))
        {
            velocity.X = -Speed;
        }
        else if (Input.IsKeyPressed(Key.D) || Input.IsKeyPressed(Key.Right))
        {
            velocity.X = Speed;
        }
        
        if (Input.IsKeyPressed(Key.W) || Input.IsKeyPressed(Key.Up))
        {
            velocity.Y = -Speed;
        }
        else if (Input.IsKeyPressed(Key.S) || Input.IsKeyPressed(Key.Down))
        {
            velocity.Y = Speed;
        }
        
        // 直接设置位置而不是使用物理系统
        Position += velocity * (float)delta;
        
        // 限制玩家在屏幕范围内
        Position = new Vector2(
            Mathf.Clamp(Position.X, 50, 1230),
            Mathf.Clamp(Position.Y, 50, 670)
        );
    }
} 